package caro.app.business;
import java.net.Socket;
import java.util.*;
/**
 * Class PlayerManagement
 * @author Thanh Nhan
 * @Since Aug 15, 2011
 * @Version 1.0
 */
public class PlayerManagement {
    private List<Player> players = null;
    public PlayerManagement(){
        players = new LinkedList<Player>();
    }
    public void addPlayer(Player player){
        players.add(player);
    }
    public void removePlayer(Player player){
        players.remove(player);
    }
    public Player findPlayer(String name){
        Iterator<Player> iter = players.iterator();
        while(iter.hasNext()){
            Player p = iter.next();
            if(p.getName().equals(name))
                return p;
        }
        return null;
    }
    public Player findPlayer(Socket socket){
        Iterator<Player> iter = players.iterator();
        while(iter.hasNext()){
            Player p = iter.next();
            if(p.getSocket().equals(socket))
                return p;
        }
        return null;
    }
    public List<Player> getList(){
        return players;
    }
}
